package com.tx.servicemember.mapper;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.springframework.data.repository.query.Param;

import com.tx.memberdto.input.dto.UserInpDTO;
import com.tx.memberdto.out.dto.UserOutDTO;
import com.tx.servicemember.mapper.entity.UserDo;

/***
 * @Author Sunny
 * @Description //TODO  用户Mapper
 * @Date 11:14 2019/9/17
 * @Param
 * @return
 */
public interface UserMapper {

	@Insert("INSERT INTO `dhcc_user` VALUES (null,#{mobile}, #{email}, #{password}, #{userName}, 0, null, null, '1', null, null, null);")
	int register(UserInpDTO userEntity);

	@Select("SELECT * FROM dhcc_user WHERE MOBILE=#{mobile};")
	UserOutDTO existMobile(@Param("mobile") String mobile);

	@Select("SELECT USER_ID AS USERID ,MOBILE AS MOBILE,EMAIL AS EMAIL,PASSWORD AS PASSWORD, USER_NAME AS USER_NAME ,SEX AS SEX ,AGE AS AGE ,CREATE_TIME AS CREATETIME,IS_AVALIBLE AS ISAVALIBLE,PIC_IMG AS PICIMG,QQ_OPENID AS QQOPENID,WX_OPENID AS WXOPENID "
			+ "  FROM dhcc_user  WHERE MOBILE=#{0} and password=#{1};")
	UserDo login(@Param("mobile") String mobile, @Param("password") String password);

	@Select("SELECT USER_ID AS USERID ,MOBILE AS MOBILE,EMAIL AS EMAIL,PASSWORD AS PASSWORD, USER_NAME AS USER_NAME ,SEX AS SEX ,AGE AS AGE ,CREATE_TIME AS CREATETIME,IS_AVALIBLE AS ISAVALIBLE,PIC_IMG AS PICIMG,QQ_OPENID AS QQOPENID,WX_OPENID AS WXOPENID"
			+ " FROM dhcc_user WHERE user_Id=#{userId}")
	UserDo findByUserId(@Param("userId") Long userId);
}
